package com.caigou.modules.article.ui

import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Route
import com.caigou.comm.base.bean.AppBackgroundInfo
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseReplyActivity
import com.caigou.comm.base.ext.observe
import com.caigou.modules.article.viewmodel.CommentViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.io.File

/**
 * @author #Suyghur.
 * Created on 2021/11/27
 */
@Route(path = RouterPath.Article.PAGE_COMMENT_REPLY)
@AndroidEntryPoint
class ArticleCommentReplyActivity : BaseReplyActivity() {

    private val commentViewModel: CommentViewModel by viewModels()

    override fun initView() {
        super.initView()

        binding.replyBtnSubmit.setOnClickListener {
            val content = binding.replyBtnSubmit.text.toString()
            val files: MutableList<File> = mutableListOf()
            urls.forEach {
                files.add(File(it))
            }
            commentViewModel.setCommentReply(
                content, files, AppBackgroundInfo.instance.userBean!!.userId,
                itemBean.replyUserInfoVo.userId, itemBean.dataId, rootItemBean.replyId
            )
        }
    }

    override fun observeViewModel() {
        observe(commentViewModel.commentReplyLiveData, ::handleSetReply)
    }
}